/*
 * Camera.cpp
 *
 *  Created on: 04.06.2011
 *      Author: kirill
 */

#include "Camera.hpp"

CGameCamera::CGameCamera()
{
	eye = vec3( -0.6f, -0.6f, -2.0f );
	center = vec3( 0.0f, 0.0f, 0.0f);
	up = vec3( 1.0f, 0.0f, 0.0f);
	viewMatrix = glm::lookAt( eye, center, up );
}

vec3
CGameCamera::RotateAroundPoint( vec3 Obj, vec3 Point, const float angelX, const float angelY, const float angelZ  )
{
	vec3 tmpVec = Obj - Point;

	tmpVec = glm::gtx::rotate_vector::rotate( tmpVec, angelX , glm::vec3(1.0f, 0.0f, 0.0f) );
	tmpVec = glm::gtx::rotate_vector::rotate( tmpVec, angelY , glm::vec3(0.0f, 1.0f, 0.0f) );
	tmpVec = glm::gtx::rotate_vector::rotate( tmpVec, angelZ , glm::vec3(0.0f, 0.0f, 1.0f) );

	tmpVec += Point;
	return tmpVec;
}

void
CGameCamera::Translate( const float dx, const float dy, const float dz )
{
	vec3 tmpVec = glm::vec3(dx, dy, dz);
	eye += tmpVec;
	center += tmpVec;
	viewMatrix = glm::lookAt( eye, center, up );
}

void
CGameCamera::RotateEyeAroundCenter( const float angelX, const float angelY, const float angelZ )
{
	eye = RotateAroundPoint( eye, center, angelX, angelY, angelZ );
	viewMatrix = glm::lookAt( eye, center, up );
}

void
CGameCamera::RotateCenterAroundEye( const float angelX, const float angelY, const float angelZ )
{
	center = RotateAroundPoint( center, eye, angelX, angelY, angelZ );
	viewMatrix = glm::lookAt( eye, center, up );
}

